<template>
  <div class="comment-reply">
    <van-nav-bar :title="`${comment.reply_count}条回复`">
      <van-icon slot="left" name="cross" @click="$emit('close')"></van-icon>
    </van-nav-bar>
     <comment-item :comment="comment"></comment-item>
      <comment-list
        :source="comment.com_id"
        type="c"
        :list="commentList"
        title="全部回复"
      ></comment-list>
    <div class="article-bottom">
      <van-button
        class="comment-btn"
        type="default"
        round
        size="small"
        @click="isPostShow = true"
      >写评论</van-button>
    </div>
    <van-popup
      v-model="isPostShow"
      get-container="body"
      position="bottom"
    ><post-comment
      :target="comment.com_id"
      :article-id="articleId"
      placeholder="请输入回复"
      @post-success='onPostSuccess'
    ></post-comment></van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
import PostComment from './post-comment.vue'
export default {
  name: 'CommentReply',
  props: {
    comment: {
      type: Object,
      required: true
    },
    articleId: {
      type: [Number, String, Object],
      required: true
    }
  },
  components: {
    CommentList,
    CommentItem,
    PostComment
  },
  data () {
    return {
      isPostShow: false,
      commentList: []
    }
  },
  computed: {},
  watch: {},
  methods: {
    onPostSuccess (comment) {
      this.commentList.unshift(comment)
      this.comment.reply_count++
      this.isPostShow = false
    }
  },
  created () {
  },
  mounted () {
  },
  destroyed () {
  }
}
</script>

<style scoped lang='less'>
.comment-reply {
  .article-bottom {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    // box-sizing: border-box;
    height: 49px;
    border-top: 1px solid #d8d8d8;
    background-color: #ffffff;
    .comment-btn {
      width: 200px;
      height: 30px;
      border: 2px solid #eeeeee;
      font-size: 15px;
      line-height: 46px;
      color: #a7a7a7;
    }
  }
}
</style>
